﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
    var list = new Array();
    
    
    function selectItem() {

        var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
        xmlDoc.async = false;
        xmlDoc.load("Browser.xml");
        //alert("Hello");
    
        /*show others lists*/
        var nomList = document.getElementById('<%=ListBox1.ClientID%>');
        var dateList = document.getElementById('<%=ListBox2.ClientID%>');
        var valueList = document.getElementById('<%=ListBox3.ClientID%>');
        var selectedValue = nomList.options[nomList.selectedIndex].value;
        
        var n = xmlDoc.documentElement.getElementsByTagName("date").length;
        var listDate = new Array();
        var listValue = new Array();
    
        for (i = 0; i < n; i++) {
            /*Find list of date*/
            var val = xmlDoc.documentElement.getElementsByTagName("date")[i].attributes.getNamedItem("nomID").value;
            if (val == selectedValue) {
                var text = xmlDoc.documentElement.getElementsByTagName("date")[i].text;
                listDate.push(text);
            }
        }
        n = xmlDoc.documentElement.getElementsByTagName("valueMone").length;
        for (i = 0; i < n; i++) {
            /*Find list of value*/
            val = xmlDoc.documentElement.getElementsByTagName("valueMone")[i].attributes.getNamedItem("nomID").value;
            if (val == selectedValue) {
                var text = xmlDoc.documentElement.getElementsByTagName("valueMone")[i].text;
                listValue.push(text);
            }
        }
    
    
        /*show list of date*/
        for (i = dateList.options.length - 1; i >= 0; i--) {
            dateList.options[i] = null;
        }
        for (i = 0; i < listDate.length; i++) {
            var dateOption = document.createElement("option");
            dateOption.text = listDate[i];
            dateList.options.add(dateOption);
        }
        /*show list of value*/
        for (i = valueList.options.length - 1; i >= 0; i--) {
            valueList.options[i] = null;
        }
        for (i = 0; i < listValue.length; i++) {
            var valueOption = document.createElement("option");
            valueOption.text = listValue[i];
            valueList.options.add(valueOption);
        }
        dateList.style.display = '';
        valueList.style.display = '';
        document.getElementById('<%=btnNewDate.ClientID%>').style.display = '';
        document.getElementById('<%=btnNewValue.ClientID%>').style.display = '';
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Displaying XML Data in a ListBox</title>
</head>
<body>    
    <form id="form1" runat="server">
    <div align="center">
        <asp:Panel ID="pnForm" runat="server" BackColor="#95D0D0" BorderColor="#CCFFCC" 
        BorderStyle="Double" BorderWidth="4px" Width="590px" 
        HorizontalAlign="Left" style="padding:20px 0 20px 0">
            &nbsp;
            <asp:Button ID="btnNewItem" runat="server" BorderStyle="Solid" 
                Text="New Item" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnNewDate" runat="server" BorderStyle="Solid" 
                Text="New Date" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnNewValue" runat="server" BorderStyle="Solid" 
                Text="New Value" />
            <br />
            &nbsp;
            <asp:ListBox ID="ListBox1" runat="server" DataTextField="desc" 
                DataValueField="value" Height="130px" OnClick="selectItem()" Width="180px">
            </asp:ListBox>
            &nbsp;&nbsp;
            <asp:ListBox ID="ListBox2" runat="server" Height="130px" Width="180px">
            </asp:ListBox>
            &nbsp;&nbsp;
            <asp:ListBox ID="ListBox3" runat="server" Height="130px" Width="180px">
            </asp:ListBox>
            <br />
            &nbsp;
            <asp:MultiView ID="Editor" runat="server">
                <asp:View ID="Item" runat="server">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </asp:View>
                <asp:View ID="Date" runat="server">
                </asp:View>
                <asp:View ID="Value" runat="server">
                </asp:View>
            </asp:MultiView>
        </asp:Panel>
    </div>

    <div>
        &nbsp;</div>
    </form>
</body>
</html>
